package com.openvas.controller;

import java.util.List;
//    import org.apache.shiro.authz.annotation.RequiresPermissions;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.openvas.commons.common.annotation.Log;
import com.openvas.commons.common.enums.BusinessType;
import com.openvas.domain.TableTask;
import com.openvas.service.ITableTaskService;
import com.openvas.commons.common.core.controller.BaseController;
import com.openvas.commons.common.core.domain.AjaxResult;

import com.openvas.commons.common.core.page.TableDataInfo;

/**
 * 扫描任务Controller
 * 
 * @author ruoyi
 * @date 2021-11-04
 */
@Controller
@RequestMapping("/api/task")
public class TableTaskController extends BaseController
{
    @Autowired
    private ITableTaskService tableTaskService;


    /**
     * 任务列表获取
     * @param tableTask
     * @return
     */
   // //  @RequiresPermissions("system:task:view")
    @ApiOperation("获取任务列表")
    @GetMapping("/findTaskList")
    public TableDataInfo task(TableTask tableTask)
    {
        startPage();
        List<TableTask> tableTasks = tableTaskService.selectTableTaskList(tableTask);
        return getDataTable(tableTasks);
    }

    /**
     * 查询扫描任务列表
     */
   // //  @RequiresPermissions("system:task:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TableTask tableTask)
    {
        startPage();
        List<TableTask> list = tableTaskService.selectTableTaskList(tableTask);
        return getDataTable(list);
    }

    /**
     * 导出扫描任务列表
     */
   // //  @RequiresPermissions("system:task:export")
    @Log(title = "扫描任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TableTask tableTask)
    {
        List<TableTask> list = tableTaskService.selectTableTaskList(tableTask);
//        ExcelUtil<TableTask> util = new ExcelUtil<TableTask>(TableTask.class);
//        return util.exportExcel(list, "扫描任务数据");
        return null;
    }

    /**
     * 新增保存扫描任务
     */
   // //  @RequiresPermissions("system:task:add")
    @Log(title = "扫描任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TableTask tableTask)
    {
        return toAjax(tableTaskService.insertTableTask(tableTask));
    }

    /**
     * 修改扫描任务
     */
    @GetMapping("/edit/{taskId}")
    public String edit(@PathVariable("taskId") String taskId, ModelMap mmap)
    {
        TableTask tableTask = tableTaskService.selectTableTaskByTaskId(taskId);
        mmap.put("tableTask", tableTask);
        return prefix + "/edit";
    }

    /**
     * 修改保存扫描任务
     */
   // //  @RequiresPermissions("system:task:edit")
    @Log(title = "扫描任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TableTask tableTask)
    {
        return toAjax(tableTaskService.updateTableTask(tableTask));
    }

    /**
     * 删除扫描任务
     */
   // //  @RequiresPermissions("system:task:remove")
    @Log(title = "扫描任务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tableTaskService.deleteTableTaskByTaskIds(ids));
    }
}
